/**
 * 实现背景
 * 创建者：Carburn ashroom
 * 2024.1.1
 */

package Background;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class BackGround implements BackGroundConfig {       // BackGround类是一个背景

    private final BufferedImage backImage = ImageIO.read(new File(PATH));
    private final int width = WIDTH;
    private final int height;

    public BackGround() throws IOException {
        height = width * backImage.getHeight() / backImage.getWidth();
    }

    public Dimension getSize() {
        return new Dimension(width, height);
    }

    public void draw(BufferedImage frame) {     // 绘制
        Graphics2D g = (Graphics2D) frame.getGraphics();
        g.drawImage(backImage, 0, 0, width, height, null);
    }

}
